<!DOCTYPE html>
<html>
  <head>
    <meta name="layout" content="main" />
    <title>Documentos guardados</title>
    <script type="text/javascript" src="${resource(dir: 'js', file: 'gd.js')}"></script>
    <script type="text/javascript">
    function previewDocument(documentId) {
        console.debug(documentId);
        var baseUrl = '<g:createLink controller="document" action="openFileFromRepository" />';
        var url = baseUrl + '/' + documentId;
        var previewer = GD.DocumentPreviewer();
        previewer.previewDocument(url, 'Documento');
    }

	function loadDocumentDetail(documentId) {
		$('#detalleDocumentoModal').load("${createLink(controller:'consultaDocumentos', action:'modalShow')}",
				"id=" + documentId)
		$('#detalleDocumentoModal').modal('show')

		return false
	}
    </script>
  </head>
  <body>
    <div class="container">
    <div class="main-panel">
    <div class="panel panel-default">
    <div class="panel-heading"><h2>Últimos (${documents.size()}) documentos guardados</h2>
    </div>
    <div class="panel-body">
    
    <g:if test="${flash.success}">
    <div class="alert alert-success">${flash.message}</div> 
    </g:if>
    <g:elseif test="${flash.message}">
    <div class="alert alert-danger">${flash.message}</div> 
    </g:elseif>

    <p><a class="btn btn-primary" role="button" href="${createLink(controller: 'document', action: 'createNew', params: [fileType: "ALTA", gd: 2])}">Cargar nuevo</a></p>
    <table class="table table-hover table-condensed">
        <thead>
            <tr>
              <th>Cliente</th>
              <th>Tipo de documento</th>
              <th>Caja AdeA</th>
              <th>Fecha de carga</th>
              <%--th>Vencimiento</th--%>
              <th>Versión</th>
              <th></th>
            </tr>
        </thead>
        <tbody>
        <g:each in="${documents}" var="document">
            <tr ${flash.document?.id == document.id ? 'class="success"' : ''}>
                <td>${document.customer.idPersona} (${document.customer.name}, CUIT: ${document.customer.cuit})</td>
                <td>${document.documentType.name}</td>
                <td>${document.box.cajaId}</td>
                <td><g:formatDate format="dd-MM-yyyy HH:mm:ss" date="${document.createdDate}"/></td>
                <%--td><g:formatDate format="dd-MM-yyyy" date="${document.validTo}"/></td--%>
                <td>${document.realVersion}</td>
				<td class="col-md-2">
					<button type="button" class="btn btn-default" onclick="previewDocument('${document.id}')"><span class="glyphicon glyphicon-eye-open"></span></button>
					<a href="#" onclick="return loadDocumentDetail(${document.id})" class="btn btn-default"><span class="glyphicon glyphicon-info-sign"></span></a>
				</td>
            </tr>
        </g:each>
        </tbody>
    </table>

    </div>
    </div>
    </div>
    </div>
    <div class="modal fade" id="detalleDocumentoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
  </body>
</html>
